package com.wswy.wzcx.ui.dmv;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.che.libcommon.api.page.PageAdapterWrapper;
import com.che.libcommon.api.page.Pagination;
import com.wswy.wzcx.R;
import com.wswy.wzcx.model.dmv.DepartmentInfo;
import com.wswy.wzcx.ui.dmv.DepartmentAdapter.ViewHolder;

class DepartmentAdapter extends PageAdapterWrapper<DepartmentInfo,ViewHolder> {


  DepartmentAdapter(
      Pagination<DepartmentInfo> pagination) {
    super(pagination);
  }

  @NonNull
  @Override
  public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_layout_dvm,parent,false));
  }

  @Override
  public void onBindViewHolder(@NonNull ViewHolder holder, int position,DepartmentInfo departmentInfo) {
    Context context = holder.itemView.getContext();
    holder.tvName.setText(departmentInfo.name);
    holder.tvTel.setText(context.getString(R.string.dvm_tel,departmentInfo.tel));
    holder.tvDistance.setText(context.getString(R.string.distance_km,departmentInfo.distancKM));
  }


  static class ViewHolder extends RecyclerView.ViewHolder{
    TextView tvName;

    TextView tvTel;

    TextView tvDistance;

    public ViewHolder(View itemView) {
      super(itemView);
      tvName = itemView.findViewById(R.id.tv_name);
      tvTel = itemView.findViewById(R.id.tv_tel);
      tvDistance = itemView.findViewById(R.id.tv_distance);

    }
  }
}
